
import numpy as np
from PIL import Image
import cv2


def get_boundary(mask, thicky=5):
	_, contour, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
	tempb = np.zeros_like(mask)
	tempb = cv2.drawContours(tempb, contour, -1, 255, thicky)
	return tempb


path = r"E:\Dataset\temp\skin\mask\f1\ISIC_0000000_segmentation.png"
path1 = r"E:\Dataset\temp\skin\boundary\f1\ISIC_0000000_segmentation.png"
path2 = r"E:\Dataset\temp\skin\boundary\f1\ISIC_0000000_boundary.png"


# img1 = Image.open(path1)
# img2 = Image.open(path2)
#
# if img1 == img2:
# 	print("相同 1")
#
# img1 = np.array(img1)
# img2 = np.array(img2)
#
# if img1.any() == img2.any():
# 	print("相同 2")
# if img1.all() == 0 or img1.all() == 255:
# 	print(" 0 and 255")


mask = Image.open(path)
mask = np.array(mask)

boundary = get_boundary(mask)
cv2.imshow("34", boundary)


mask2 = cv2.resize(boundary, (256, 256))
cv2.imshow("1233sdfsd434", mask2)
cv2.waitKey(0)

path2 = path.replace("mask", "boundary")
path2 = path2.replace("segmentation", "boundary")

cv2.imwrite(path2, boundary)

